//
//  BorrowReasonVC.m
//  BrushFace
//
//  Created by timer_q on 15/12/11.
//  Copyright © 2015年 Zzz. All rights reserved.
//

#import "BorrowReasonVC.h"
#import "IWillHelper.h"

@interface BorrowReasonVC ()<UITextViewDelegate>
{
    __weak IBOutlet UIButton *lvyouButton;
    __weak IBOutlet UIButton *zufangButton;
    __weak IBOutlet UIButton *shenghuofeiButton;
    __weak IBOutlet UIButton *zhouzhuanButton;
    __weak IBOutlet UIButton *xuexiButton;
    __weak IBOutlet UIButton *shoujiButton;
    __weak IBOutlet UITextView *textView;
    NSInteger _reasonID;
    NSArray *_buttonArray;
}
@end

@implementation BorrowReasonVC

- (void)viewDidLoad {
    [super viewDidLoad];
    [self dataInit];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
#pragma mark - dataInit
- (void)dataInit{
    [self.navBar setTitle:@"借款理由"];
    [self.navBar setLeftBtn:NAV_BAR_LEFT_BTN_TYPE_BLUE];
    UIButton *rightButton = [UIButton buttonWithType:UIButtonTypeSystem];
    rightButton.frame = CGRectMake(0, 20, 60, 44);
    [rightButton setTitleColor:ColorDefaultBlue forState:UIControlStateNormal];
    [rightButton setTitle:@"确定" forState:UIControlStateNormal];
    [rightButton addTarget:self action:@selector(doneButtonClick:) forControlEvents:UIControlEventTouchUpInside];
    [self.navBar setRightView:rightButton];
    
    if ([IWillHelper sharedInstance].reasonID != 6) {
        textView.text = @"";
        _buttonArray  = @[zufangButton,xuexiButton,lvyouButton,shoujiButton,shenghuofeiButton,zhouzhuanButton];
        [IWillHelper helperReasonButtonSelectButton:[_buttonArray objectAtIndex:[IWillHelper sharedInstance].reasonID] withButtonArray:_buttonArray];
    }else{
        textView.text = @"";
    }
}
#pragma mark - action
- (void)doneButtonClick:(UIButton *)sender{
    if ([textView.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]].length == 0||textView.text.length == 0) {
        [IWillHelper sharedInstance].reasonID = _reasonID;
    }else{
        [IWillHelper sharedInstance].reasonDetail = [[NSString alloc]initWithString:textView.text];
        [IWillHelper sharedInstance].reasonID = 6;
    }
    
    [self.navigationController popViewControllerAnimated:YES];
}
- (IBAction)lvyouButtonClick:(id)sender {
    _reasonID = 2;
    [IWillHelper helperReasonButtonSelectButton:sender withButtonArray:_buttonArray];
}
- (IBAction)zufangButtonClick:(id)sender {
    _reasonID = 0;
    [IWillHelper helperReasonButtonSelectButton:sender withButtonArray:_buttonArray];
}
- (IBAction)shenghuofeiButtonClick:(id)sender {
    _reasonID = 4;
    [IWillHelper helperReasonButtonSelectButton:sender withButtonArray:_buttonArray];
}
- (IBAction)zhouzhuanButtonClick:(id)sender {
    _reasonID = 5;
    [IWillHelper helperReasonButtonSelectButton:sender withButtonArray:_buttonArray];
}
- (IBAction)xuexiButtonClick:(id)sender {
    _reasonID = 1;
    [IWillHelper helperReasonButtonSelectButton:sender withButtonArray:_buttonArray];
}
- (IBAction)shoujiButtonClick:(id)sender {
    _reasonID = 3;
    [IWillHelper helperReasonButtonSelectButton:sender withButtonArray:_buttonArray];
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
